Jan-Philipp Kolb
7 Februar 2017
D3 ist eine der mächtigsten unter der Vielzahl aktuell verfügbarer JavaScript-Bibliotheken zur Datenvisualisierung.
D3, ggplot2 und RStudiomtcars %>%
ggvis(~wt, ~mpg, fill = ~factor(cyl)) %>%
layer_points() %>%
group_by(cyl) %>%
layer_model_predictions(model = "lm")ggvismtcars %>%
ggvis(~wt, ~mpg) %>%
layer_smooths(span = input_slider(0.5, 1, value = 1)) %>%
layer_points(size := input_slider(100, 1000, value = 100))install.packages("googleVis")library(googleVis)googleVis bietet eine Schnittstelle zur Google Charts APIgoogleVisgoogleVislibrary(DT)
datatable(Fruits)googleVisplot(gvisMotionChart(Fruits, "Fruit", "Year", options = list(width = 600, height = 400)))df <- data.frame(year=1:11, x=1:11,
x.scope=c(rep(TRUE, 8), rep(FALSE, 3)),
y=11:1, y.html.tooltip=LETTERS[11:1],
y.certainty=c(rep(TRUE, 5), rep(FALSE, 6)),
y.emphasis=c(rep(FALSE, 4), rep(TRUE, 7)))googleVisplot(gvisScatterChart(df,options=list(lineWidth=2)))clickmelibrary(clickme)
clickme("points", 1:10)clickme Beispieln <- 500
clickme("points",
x = rbeta(n, 1, 10), y = rbeta(n, 1, 10),
names = sample(letters, n, r = T),
color_groups = sample(LETTERS[1:3], n, r = T),
title = "Zoom Search Hover Click")networkD3library(networkD3)
src <- c("A", "A", "A", "A",
"B", "B", "C", "C", "D")
target <- c("B", "C", "D", "J",
"E", "F", "G", "H", "I")
networkData <- data.frame(src, target)
# Plot
simpleNetwork(networkData)sink("FirstNetwork.js")
writeLines(d3SimpleNetwork(NetworkData), fileConn)
unlink("FirstNetwork.js")library(dygraphs)
dygraph(nhtemp, main = "New Haven Temperatures") %>%
dyRangeSelector(dateWindow = c("1920-01-01", "1960-01-01"))library(googleVis)
op <- options(gvis.plot.tag = "chart")
## Add the mean
CityPopularity$Mean=mean(CityPopularity$Popularity)
CC <- gvisComboChart(CityPopularity, xvar='City',
yvar=c('Mean', 'Popularity'),
options=list(seriesType='bars',
width=450, height=300,
title='City Popularity',
series='{0: {type:\"line\"}}'))
plot(CC)## <!-- ComboChart generated in R 3.3.3 by googleVis 0.6.2 package -->
## <!-- Sun May 07 09:28:23 2017 -->
##
##
## <!-- jsHeader -->
## <script type="text/javascript">
##
## // jsData
## function gvisDataComboChartID21b069f54aa2 () {
## var data = new google.visualization.DataTable();
## var datajson =
## [
## [
## "New York",
## 450,
## 200
## ],
## [
## "Boston",
## 450,
## 300
## ],
## [
## "Miami",
## 450,
## 400
## ],
## [
## "Chicago",
## 450,
## 500
## ],
## [
## "Los Angeles",
## 450,
## 600
## ],
## [
## "Houston",
## 450,
## 700
## ]
## ];
## data.addColumn('string','City');
## data.addColumn('number','Mean');
## data.addColumn('number','Popularity');
## data.addRows(datajson);
## return(data);
## }
##
## // jsDrawChart
## function drawChartComboChartID21b069f54aa2() {
## var data = gvisDataComboChartID21b069f54aa2();
## var options = {};
## options["allowHtml"] = true;
## options["seriesType"] = "bars";
## options["width"] = 450;
## options["height"] = 300;
## options["title"] = "City Popularity";
## options["series"] = {0: {type:"line"}};
##
##
## var chart = new google.visualization.ComboChart(
## document.getElementById('ComboChartID21b069f54aa2')
## );
## chart.draw(data,options);
##
##
## }
##
##
## // jsDisplayChart
## (function() {
## var pkgs = window.__gvisPackages = window.__gvisPackages || [];
## var callbacks = window.__gvisCallbacks = window.__gvisCallbacks || [];
## var chartid = "corechart";
##
## // Manually see if chartid is in pkgs (not all browsers support Array.indexOf)
## var i, newPackage = true;
## for (i = 0; newPackage && i < pkgs.length; i++) {
## if (pkgs[i] === chartid)
## newPackage = false;
## }
## if (newPackage)
## pkgs.push(chartid);
##
## // Add the drawChart function to the global list of callbacks
## callbacks.push(drawChartComboChartID21b069f54aa2);
## })();
## function displayChartComboChartID21b069f54aa2() {
## var pkgs = window.__gvisPackages = window.__gvisPackages || [];
## var callbacks = window.__gvisCallbacks = window.__gvisCallbacks || [];
## window.clearTimeout(window.__gvisLoad);
## // The timeout is set to 100 because otherwise the container div we are
## // targeting might not be part of the document yet
## window.__gvisLoad = setTimeout(function() {
## var pkgCount = pkgs.length;
## google.load("visualization", "1", { packages:pkgs, callback: function() {
## if (pkgCount != pkgs.length) {
## // Race condition where another setTimeout call snuck in after us; if
## // that call added a package, we must not shift its callback
## return;
## }
## while (callbacks.length > 0)
## callbacks.shift()();
## } });
## }, 100);
## }
##
## // jsFooter
## </script>
##
## <!-- jsChart -->
## <script type="text/javascript" src="https://www.google.com/jsapi?callback=displayChartComboChartID21b069f54aa2"></script>
##
## <!-- divChart -->
##
## <div id="ComboChartID21b069f54aa2"
## style="width: 450; height: 300;">
## </div>
install.packages("threejs")# install.packages("threejs")
library(threejs)
z <- seq(-10, 10, 0.01)
x <- cos(z)
y <- sin(z)
scatterplot3js(x,y,z, color=rainbow(length(z)))